<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .item {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 100px;
            top: 100px;
            border: 2px solid;
            background: #000;
        }
    </style>
</head>

<body>
    <div class="item">

    </div>
    <p>
        <button id="btnBegin">开始</button>
        <button id="btnStop">停止</button>
    </p>
    <script src="../../plugin/helpers.js"></script>
    <script src="../../plugin/animate.js"></script>
    <script>
        var div = document.querySelector("div");
        var animate = new this.myPlugin.Animate({
            duration: 30,
            total: 5000,
            begin: {
                left: 100,
                top: 100,
                r: 0,
                g: 0,
                b: 0
            },
            end: {
                left: 1000,
                top: 500,
                r: 200,
                g: 200,
                b: 200
            },
            onstart: function() {
                console.log("开始");
            },
            //当每次发生变化时
            onmove: function() {
                div.style.left = this.curData.left + "px";
                div.style.top = this.curData.top + "px";
                div.style.background = `rgb(${this.curData.r},${this.curData.g},${this.curData.b})`;
            },
            //结束事件
            onover: function() {
                console.log("结束");
            }
        });

        btnBegin.onclick = function() {
            animate.start();
        }

        btnStop.onclick = function() {
            animate.stop();
        }
    </script>
</body>

</html>
